package com.itheima.config;

import com.itheima.controller.interceptor.ProjectInterceptor;
import com.itheima.controller.interceptor.ProjectInterceptor2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * Description:
 *
 * @author codermao
 * @date 2023/11/8 15:15
 */
@Configuration
public class SpringMvcSupport extends WebMvcConfigurationSupport {

    //TODO
    @Autowired
    private ProjectInterceptor projectInterceptor;
    @Autowired
    private ProjectInterceptor2 projectInterceptor2;

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");
        registry.addResourceHandler("/css/**").addResourceLocations("/css/");
        registry.addResourceHandler("/js/**").addResourceLocations("/js/");
        registry.addResourceHandler("/plugins/**").addResourceLocations("/plugins/");
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        //TODO: 配置拦截器 : 此拦截器的拦截路径是/books，还有/books/*
        registry.addInterceptor(projectInterceptor).addPathPatterns("/books","/books/*");
        //拦截器链
        //多个拦截器先配置的先执行preHandle，后配置的先执行postHandle和afterHandle
        registry.addInterceptor(projectInterceptor2).addPathPatterns("/books");
    }
}